# -*- coding: UTF-8 -*-
"""
@author: tgy
@file: 1004_最大连续1的个数_III.py
@time: 2021/02/19
"""


class Solution:
    def longestOnes(self, A: list, K: int) -> int:
        ...
        one_num = 0
        a_len = len(A)
        left = 0
        right = 0
        while right < a_len:
            ...
            if A[right] == 1:
                ...
                one_num += 1

            if right - left + 1 - one_num > K:
                ...
                if A[left] == 1:
                    one_num -= 1
                left += 1

            right += 1
        return right - left


if __name__ == '__main__':
    pass
    solution = Solution()
    a = [0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1]
    k = 3
    result = solution.longestOnes(a, k)
    print(result)
